﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using Yipusoft.SecurityEvaluate;


public partial class DutyLog_DutyView1 : System.Web.UI.Page
{
    private string DepartmentID;
    string[] strCol = new string[] { "班长", "驾驶员", "一号员", "二号员", "三号员", "四号员", "五号员", "六号员" };
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request["DepartmentID"] != null)
        {
            DepartmentID = Request["DepartmentID"];
            lblCaption.Text = Yipusoft.Account.BLL.Department.GetDepartment(DepartmentID).FullName;
        }
        if (!IsPostBack)
            Bind();
    }
    private DutyLogs GetDutyLog()
    {
        if (DepartmentID == null)
            return null;
        return Duty.GetDutyLog(DateTime.Parse(Request["Date"]), DepartmentID);
    }

    private List<DutyCar> GetDutyCar(Guid dID)
    {
        return Duty.GetDutyCar(dID);
    }

    private IEnumerable<CodeName> GetDutyCodeName(Guid cID)
    {
        return Duty.GetCodeName(cID);
    }

    public string GetHeader()
    {

        DutyLogs log = GetDutyLog();
        if (log == null)
            return "";

        string str = string.Empty;

        str += "<tr><td>执勤队长</td><td>通信员</td><td>战勤员</td><td>中队总人数</td><td>执勤人数</td><td>公差</td><td>公休</td><td>其它</td></tr>";
        str += "<tr><td>" + log.Captain + "</td><td>" + log.Signalman + "</td><td>" + log.Combatant + "</td><td>" + log.Lochus + "</td><td>" + log.DutyCount + "</td><td>" + log.ToleranceCount + "</td><td>" + log.RestCount + "</td><td>" + log.Orther + "</td></tr>";
        return str;
    }

    public string SetDate()
    {
        DutyLogs duty = GetDutyLog();
        if (duty == null)
            return "";
        return duty.StartTime.Value.ToString() + "--" + duty.EndTime.Value.ToString();
    }
    private void Bind()
    {

        DutyLogs duty = GetDutyLog();
        if (duty == null)
            return;

        List<DutyCar> listCar = GetDutyCar(duty.ID);
        listCar = (from o in listCar orderby o.OrderID ascending select o).ToList();
        rpt.DataSource = listCar;
        rpt.DataBind();

    }


    public string SetItem(object objID, object objDutyCar, object objEqCar, object objKinds, object orderID)
    {
        if (objID == null)
            return "";
        string str = string.Empty;

        List<CodeName> listName = GetDutyCodeName(new Guid(objID.ToString())).ToList();
        str = " <tr> <td colspan=\"2\"> " + orderID + "&nbsp; </td> <td colspan=\"2\"> " + objKinds + "</td>  <td colspan=\"2\"> " + objDutyCar + " </td> <td colspan=\"2\"> " + objEqCar + " </td>   </tr>";
        str += "<tr>";
        for (int i = 0; i < 8; i++)
        {
            str += "<td>" + strCol[i] + "</td>";
        }
        str += "</tr>";

        str += "<tr>";
        for (int i = 0; i < 8; i++)
        {
            CodeName cn = listName.Where(o => o.OrderID2 == i).FirstOrDefault();
            if (cn == null)
            {
                str += "<td></td>";
            }
            else
            {
                str += "<td>" + cn.Name + "</td>";
            }


        }
        str += "</tr>";
        return str;


    }
    protected void rpt_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }
}
